﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using cs499.Database;

namespace cs499.Locations
{
    public partial class DeleteLocations : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void CancelButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Locations/ListLocations.aspx");
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            LinkButton locationsMenuButton = (LinkButton)Master.FindControl("LoginView").FindControl("LocationsMenuButton");
            locationsMenuButton.CssClass = "selected";

            if (HttpContext.Current.Session["CurrentDepartmentId"] != null)
            {
                int CurrentDepartmentId = (int)HttpContext.Current.Session["CurrentDepartmentId"];
                cs499.Database.Department CurrentDepartment = ListOfDepartment.GetDepartment(ID: CurrentDepartmentId);
                //EntityDataSource1.Where = "it.DepartmentId=" + (CurrentDepartment.Id).ToString();
                DepartmentLabel.Text = CurrentDepartment.Name;

            }
            else
            {
                DepartmentLabel.Text = "(No departments defined)";
            }
        }

        protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int CurrentDepartmentId = (int)HttpContext.Current.Session["CurrentDepartmentId"];
            int buildingid = (int)GridView1.DataKeys[e.RowIndex].Value;
            cs499.Database.ListOfDepartment.GetDepartment(ID: CurrentDepartmentId).DeletePlace(ID: buildingid);
            //cs499.Database.ListOfDepartment.GetDepartment(ID: CurrentDepartmentId).Places.Remove();
            e.Cancel = true;
            Response.Redirect("~/Locations/DeleteLocations.aspx");
        }

        protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int CurrentDepartmentId = (int)HttpContext.Current.Session["CurrentDepartmentId"];
            int roomid = (int)GridView2.DataKeys[e.RowIndex].Value;
            cs499.Database.ListOfDepartment.GetDepartment(ID: CurrentDepartmentId).DeletePlace(ID: roomid);
            e.Cancel = true;
            Response.Redirect("~/Locations/DeleteLocations.aspx");
        }

        protected void GridView2_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            
        }
    }
}